<template>
	<view class="content" v-if="IsShowMain">
		<view class="userinfo">
			<button class="head"  open-type="getUserInfo" @getuserinfo="getuserinfo" :disabled="infoList.disabled" >
				<view class="headImg" style="margin-top: 80upx;">
					<image :src="infoList.avatar_url" mode=""></image>
				</view>
				<view class="nickName">{{infoList.nickname}}</view>
			</button>
			
		</view>
		<view>
			<zy-grid :grid-list=gridList :show-tip="true" :col="3"></zy-grid>
		</view>
		<view class='tabbar'>
			<minetab></minetab>
		</view> 
	</view>
</template>

<script>
	import {minetab} from "@/pages/tabbar/minetab.vue";
	import zyGrid from '@/components/zy-grid/zy-grid.vue';
	import uniIcon from '@/components/uni-icon/uni-icon.vue';
	import api from '@/pages/utils/api.js';
	export default {
		components: {
			minetab,
			zyGrid,
			uniIcon
		},
		data() {
			return {
				IsShowMain:false,
				infoList: {
					avatar_url: '/static/login.jpg',
					nickname: '您暂未授权（点击登录）',
					disabled: ''
				},
				gridList: [	//格子数据列表
					{
						name: '我的资料',
						imgUrl: '/static/svg/grid-02.svg',
						tips: ''
					},
					{
						name: '分销中心',
						imgUrl: '/static/svg/grid-11.svg',
						tips: ''
					},
					{
						name: '我的发布',
						imgUrl: '/static/svg/grid-09.svg',
						tips: '0'
					},
					{
						name: '平台公告',
						imgUrl: '/static/svg/grid-05.svg',
						tips: ''
					},
					{
						name: '电话客服',
						imgUrl: '/static/svg/phone.svg',
						tips: ''
					},
					{
						name: '微信客服',
						imgUrl: '/static/svg/weixn.svg',
						tips: ''
					}
				]
			}
		},
		onLoad() {
			// 查看是否授权
			var vm = this;
			wx.getSetting({
			  success (res){
				if (res.authSetting['scope.userInfo']) {
				//获取用户的基本信息	
				  wx.getUserInfo({
					success: function(res) {
					  vm.infoList.avatar_url = res.userInfo.avatarUrl;
					  vm.infoList.nickname = res.userInfo.nickName;
					  api.getIssueJobList({
					  	 page:1,
					  	 pagesize:50
					  }).then(info=>{ 
					  	if(info.code == 1 && info.data.length > 0){
					  		vm.gridList[2].tips = info.data.length
					  	}
					  });
					}
				  });
				}
			  }
			});
		},
		onShow() {
			if(uni.getStorageSync('checked_status') == 1){
				uni.navigateTo({
					url: '/pages/index/checked'
				});
				return;
			};
			// 查看是否授权
			var vm = this;
			vm.IsShowMain = true;
			wx.getSetting({
			  success (res){
				if (res.authSetting['scope.userInfo']) 
				{
				  wx.getUserInfo({
					success: function(res) {
					  vm.infoList.avatar_url = res.userInfo.avatarUrl;
					  vm.infoList.nickname = res.userInfo.nickName;
					  api.getIssueJobList({
					  	 page:1,
					  	 pagesize:50
					  }).then(info=>{ 
					  	if(info.code == 1 && info.data.length > 0){
					  		vm.gridList[2].tips = info.data.length
					  	}
					  });
					}
				  })
				}
			  }
			})
		},
		methods: {
			getuserinfo(res){//调起微信登录授权
			var vm = this;
				wx.getSetting({
					   success: function (res) {
							if (res.authSetting['scope.userInfo']) 
							{
							 wx.getUserInfo({
								  success: function (res) {
									  //记录用户身份
									  	api.getMember({}).then(info=>{
									  		if(info.code == 1){ 
									  			uni.setStorageSync('identity',info.data.type)//身份信息（企业 || 用户）
												uni.setStorageSync('isreseller',info.data.isreseller)//身份信息（分销商 || 非分销商）
									  		}
									  	});
										vm.infoList.avatar_url = res.userInfo.avatarUrl;
										vm.infoList.nickname = res.userInfo.nickName;
										api.getIssueJobList({
											 page:1,
											 pagesize:50
										}).then(info=>{ 
											if(info.code == 1 && info.data.length > 0){
												vm.gridList[2].tips = info.data.length
											}
										});
										
										//获取用户信息（判断上级）
										api.getUserInfo({
											encryptedData:res.encryptedData,
											iv:res.iv,
											sessionKey:uni.getStorageSync('session_key'),
											agentid:uni.getStorageSync('agentid') || '',
										}).then(info=>{
											if(info.code == 1){ 
												
											}
										});
								  }
							 });
							} 
					   }
				  })
			}
		}
	} 
</script>  

<style>
	.head{
		background-image: url(../../static/top.jpg);
		background-position: center;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		height: 360upx;
		
	}
	.headImg image{
		width: 120upx;
		height: 120upx;
		border-radius: 50%;
	}
	.nickName{
		font-size: 28upx;
		color:#FFF;
	}

	.tabbar{
		position: fixed;
		width: 100%;
		bottom: 0;
		background: #FFF;
	}
	
	.itemlist .mine-title{
		color:#F7AE2B
	}
</style>
